<template>
	<view class="audit-container">
		<view class="top-grade" :style="{color:courtshipDetail.audit_score>=60?'#26BCFD':'#D54941'}">{{courtshipDetail.audit_score?courtshipDetail.audit_score+'分':'暂无评分' }}</view>
		<view class="modle modle1">
			<view class="modle-title">注册信息表</view>
			<view class="personal-info">
				<view class="photo">
					<image :src="userInfo.avatar" v-if="userInfo.avatar"></image>
					<image v-else src="https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132"></image>
				</view>
				<view class="infoR">
					<view class="name-box">
						<text class="name">{{userInfo.nickname||'-'}}</text>
						<text class="time">注册{{userInfo.createtime||'-'}}</text>
					</view>
					<view class="phone">注册手机：{{userInfo.mobile||'-'}} <text v-if="userInfo.mobile">({{userInfo.mobileHome}})</text>
						<text v-if="userInfo.mobile" class="copy" @tap="copyText(userInfo.mobile)">复制</text>
					</view>
				</view>
			</view>
		</view>
		
		<view class="modle">
			<view class="modle-title">申请表</view>
			<view class="apply-info-table">
				<view class="table-item">
					<view class="lable">姓名</view>
					<view class="value">{{courtshipDetail.username||'-'}}<text v-if="courtshipDetail.username" class="copy" @tap="copyText(courtshipDetail.username)">复制</text></view>
				</view>
				<view class="table-item">
					<view class="lable">手机号</view>
					<view class="value">{{courtshipDetail.mobile||'-'}}
						<text v-if="courtshipDetail.mobile" >({{courtshipDetail.mobileHome}})</text>
						<text v-if="courtshipDetail.mobile" class="copy" @tap="copyText(courtshipDetail.mobile)">复制</text>
					</view>
				</view>
				<!-- <view class="table-item">
					<view class="lable">出生日期</view>
					<view class="value">1984-10（41岁）</view>
				</view> -->
				<view class="table-item">
					<view class="lable">申请开店省份</view>
					<view class="value">{{courtshipDetail.province||'-'}}</view>
				</view>
				<view class="table-item">
					<view class="lable">申请开店城市</view>
					<view class="value">{{courtshipDetail.city||'-'}}</view>
				</view>
				<view class="table-item">
					<view class="lable">申请开店区县</view>
					<view class="value">{{courtshipDetail.area||'-'}}</view>
				</view>
				<view class="table-item">
					<view class="lable">提交IP</view>
					<view class="value">{{courtshipDetail.submit_ip||'-'}}
						<text v-if="courtshipDetail.submit_ip">({{courtshipDetail.ipHome}})</text>
					</view>
				</view>
				<view class="table-item">
					<view class="lable">提交时间</view>
					<view class="value">{{courtshipDetail.createtime?this.$tools.formatDate(courtshipDetail.createtime):'-'}}</view>
				</view>
				
				<view class="table-item">
					<view class="lable">首次进入招商页面时间</view>
					<view class="value">{{timesData.first_time?this.$tools.formatDate(timesData.first_time):'-'}}</view>
				</view>
				<view class="table-item">
					<view class="lable">招商页面累计停留时间</view>
					<view class="value">{{timesData.times?this.$tools.formatSecond(timesData.times):'-'}}</view>
				</view>
				<view class="table-item">
					<view class="lable">招商页面进入次数</view>
					<view class="value">{{timesData.count||'-'}}次（最近一次{{timesData.last_time?this.$tools.formatDate(timesData.last_time):'-'}}）</view>
				</view>
			</view>
		</view>
		
		<view class="modle">
			<view class="modle-title">到过的店铺</view>
			<view class="been-shop">
				<view class="shop-item" v-for="item in wallet" :key="item.store_id">
					<view class="item-left">
						<view class="shop-name">{{item.shop_name}}</view>
						<view class="time">{{item.last_time||''}}</view>
					</view>
					<view class="item-right">
						<view class="nape">
							<view class="message">
								<text class="message-value">{{item.num}}</text>
								<text class="message-lable">到店</text>
							</view>
							<view class="message">
								<text class="message-value">{{item.amount}}</text>
								<text class="message-lable">消费</text>
							</view>
						</view>
						<view class="nape">
							<view class="message">
								<text class="message-value">{{item.store_money?item.store_money:0}}</text>
								<text class="message-lable">余额</text>
							</view>
							<view class="message">
								<text class="message-value">{{item.total}}</text>
								<text class="message-lable">通卡</text>
							</view>
						</view>
						
					</view>
				</view>
			</view>
		</view>
		
		<view class="bottom-btns">
			<view class="btn nopass" @tap="submit(2)">审核不通过</view>
			<view class="btn pass" @tap="submit(1)">审核通过</view>
		</view>
	</view>
</template>

<script>
	import MD5 from "@/common/lib/md5.js"
	export default{
		data(){
			return{
				id:'',
				courtshipDetail:{},
				userInfo:{},
				timesData:{},
				wallet:[],
			}
		},
		onLoad(options) {
			this.id=options.id
		},
		onShow(){
			this.getDetailsInfo()
		},
		methods:{
			// 申请信息详情页面
			getDetailsInfo(){
				this.$request.post(this.$api.auditDetails, {
					courtship_id:this.id
				}, {
					token: true
				}).then(async res => {
					if (res.code == 1) {
						let {
							data = {}
						} = res;
						
						let courtshipDetail=data.courtshipDetail.length>0?data.courtshipDetail[0]:{}
						if(JSON.stringify(courtshipDetail)!=='{}'){
							// 获取号码归属地
							let moblieResult=await this.getMobileHome(MD5.hex_md5(courtshipDetail.mobile))
							if(moblieResult.province==moblieResult.city){
								courtshipDetail.mobileHome=moblieResult.province
							}else{
								courtshipDetail.mobileHome=moblieResult.province+moblieResult.city
							}
							
							// 获取ip归属地
							let ipResult=await this.getIpHome(courtshipDetail.submit_ip)
							if(ipResult.province==ipResult.city){
								courtshipDetail.ipHome=ipResult.province
							}else{
								courtshipDetail.ipHome=ipResult.province+ipResult.city
							}
						}
						this.courtshipDetail=courtshipDetail
						
						let userInfo=data.userInfo.length>0?data.userInfo[0]:{}
						if(JSON.stringify(userInfo)!=='{}'){
							userInfo.createtime=this.$tools.fDate(this.$tools.formatDate(userInfo.createtime)).replace(/前/g,"")
							// 获取号码归属地
							let result1=await this.getMobileHome(MD5.hex_md5(userInfo.mobile))
							if(result1.province==result1.city){
								userInfo.mobileHome=result1.province
							}else{
								userInfo.mobileHome=result1.province+result1.city
							}
						}
						
						this.userInfo=userInfo
						
						this.timesData=data.times.length>0?data.times[0]:{}
						
						let walletData=data.wallet
						for (let i in walletData) {
							walletData[i].last_time =this.$tools.formatDate(walletData[i].last_time)	
						}
						this.wallet=walletData
						
						if(this.courtshipDetail.audit_status!=0){
							uni.redirectTo({
								url:"/pages/join/addRecord?id="+this.id
							})
						}
					}
				})
			},
			
			// 复制信息
			copyText(text){
				let that = this
				uni.setClipboardData({
					data:text,
					success: function() {
						uni.showToast({
						    title: '复制成功',
						    icon: 'success',
						    duration: 1000
						});
					}
				});
			},
			
			submit(type){
				let title=''
				if(type==2){
					title='是否不予通过？'
				}else if(type==1){
					title='是否确定通过？'
				}
				uni.showModal({
					title:title,
					success: (res) => {
						if(res.confirm){
							this.$request.post(this.$api.auditOperate, {
								courtship_id:this.id,
								status:type,
							}, {
								token: true
							}).then(res => {
								if (res.code == 1) {
									uni.redirectTo({
										url:"/pages/join/addRecord?id="+this.id
									})
								}else if(res.code==0&&res.data){
									setTimeout(()=>{
										uni.redirectTo({
											url:"/pages/join/addRecord?id="+this.id
										})
									},1000)
								}
							})
						}
					}
				})
			},
			
			// 获取手机号归属地
			getMobileHome(inputNumber){
				return this.$request.post(this.$api.mobileHome, {
					inputNumber:inputNumber,
					mask:'MD5'
				}, {
					isJava: true
				}).then(res => {
					// console.log(res,"手机号归属地")
					return res.data
				})
			},
			
			// ip归属地
			getIpHome(ip){
				return this.$request.get(this.$api.ipHome, {
					ip:ip
				}, {
					isJava: true
				}).then(res => {
					// console.log(res,"IP归属地")
					return res.data
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.bottom-btns{
		margin-top: 48rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		gap:32rpx;
		.btn{
			width: 320rpx;
			height: 80rpx;
			border-radius: 16rpx;
			font-weight: 500;
			font-size: 36rpx;
			color: #FFFFFF;
			line-height: 80rpx;
			text-align: center;
			padding: 0 16rpx;
			box-sizing: border-box;
		}
		.nopass{
			background: #D54941;
		}
		.pass{
			background: #26BCFD;
		}
	}
</style>